﻿using Cart.NguoiDungSrv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Cart
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtTuKhoa.Attributes.Add("onblur", "javascript:if(this.value == '')this.value='Nhập từ khóa';");
                txtTuKhoa.Attributes.Add("onfocus", "javascript:if(this.value == 'Nhập từ khóa') this.value='';");
                ddlGiaTu.DataSource = AddDataSource(0);
                ddlGiaTu.DataBind();
                ddlGiaTu.DataTextField = "Value";
                ddlGiaTu.DataValueField = "Key";

                ddlGiaDen.DataSource = AddDataSource(1);
                ddlGiaDen.DataBind();
                ddlGiaDen.DataTextField = "Value";
                ddlGiaDen.DataValueField = "Key";


                using (var ndService = new SanPhamSrv.SanPhamServiceClient())
                {
                    var result = ndService.DanhSachLoaiSanPham();
                    lv1.DataSource = result;
                    lv1.DataBind();
                }

            }
            var user = Session["nsd"] as NguoiDung;
            if (user == null)
            {
                plHolder.Controls.Add(LoadControl("~/Login.ascx"));
            }
            else
            {
                if (user.Quyen == 1)
                {
                    plHolder.Controls.Add(LoadControl("~/AccountAdmin.ascx"));
                }
                else
                {
                    plHolder.Controls.Add(LoadControl("~/Account.ascx"));
                }
            }
        }
        public Dictionary<string, string> AddDataSource(int i)
        {
            
            Dictionary<string, string> list = new Dictionary<string, string>();
            if (i == 0)
            {
                list.Add("", "Giá từ");
            }
            else
            {
                list.Add("", "Giá đến");
            }
            list.Add("20000", "20,000");
            list.Add("50000", "50,000");
            list.Add("100000", "100,000");
            list.Add("150000", "150,000");
            list.Add("200000", "200,000");
            list.Add("250000", "250,000");
            list.Add("300000", "300,000");
            list.Add("500000", "500,000");
            list.Add("1000000", "1,000,000");
            list.Add("3000000", "3,000,000");
            list.Add("5000000", "5,000,000");
            return list;
        }

        protected void btTimKiem_Click(object sender, EventArgs e)
        {
            string giatu = ddlGiaTu.SelectedItem.Value;
            string giaden = ddlGiaDen.SelectedItem.Value;
            string tukhoa = (txtTuKhoa.Text == "Nhập từ khóa" ? "" : txtTuKhoa.Text);
            Response.Redirect("~/TimKiem.aspx?tukhoa=" + tukhoa + "&giatu=" + giatu + "&giaden=" + giaden);
        }
    }
}